
 function saveAsLocalImage (canvas) {  
 			// var mycanvas = document.getElementById("thecanvas");  
                // var image    = canvas.toDataURL("image/png");  
                // var w=window.open('about:blank','image from canvas');  
                // w.document.write("<img src='"+image+"' alt='from canvas'/>");  
                // var myCanvas = document.getElementById("thecanvas");  
                // here is the most important part because if you dont replace you will get a DOM 18 exception.  
                // var image = myCanvas.toDataURL("image/png").replace("image/png", "image/octet-stream;Content-Disposition: attachment;filename=foobar.png");  
                var image1 = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");   
                window.location.href=image1; // it will save locally  
            } 

var renderButton = document.getElementById("render_button");
renderButton.addEventListener("click", function(){
	var renderScene = new THREE.Scene();
	for(index in scene.children){
		if(scene.children[index] instanceof THREE.Mesh){
			renderScene.add(scene.children[index]);
		}
		if(scene.children[index] instanceof THREE.Light){
			renderScene.add(scene.children[index]);
		}
	}
	var outputRender = new THREE.WebGLRenderer({antialias : true});
	// outputRenderrenderer.setSize(width,height);
	var renderScale = renderer.getSize();
	outputRender.setSize(renderScale.width,renderScale.height);
	outputRender.render(renderScene,camera);
	for(index in renderScene.children){
		if(renderScene.children[index] instanceof THREE.Mesh){
			scene.add(renderScene.children[index]);
		}
		if(renderScene.children[index] instanceof THREE.Light){
			scene.add(renderScene.children[index]);
		}
	}
	
	saveAsLocalImage (outputRender.domElement);
	render();
	console.log('canvas里已经有东西了');
});
 
